For unknown sort to bydate
[lhc/web/wiklou.git] / includes / SpecialImagelist.php
1 <?php
2
3 function wfSpecialImagelist()
4 {
5 global $wgUser, $wgOut, $wgLang, $wgRequest;
6
7 $sort = $wgRequest->getVal( 'sort' );
8 $wpIlMatch = $wgRequest->getText( 'wpIlMatch' );
9 $dbr =& wfGetDB( DB_SLAVE );
10 $image = $dbr->tableName( 'image' );
11 $sql = "SELECT img_size,img_name,img_user,img_user_text," .
12 "img_description,img_timestamp FROM $image";
13
14 $byname = wfMsg( "byname" );
15 $bydate = wfMsg( "bydate" );
16 $bysize = wfMsg( "bysize" );
17
18 if ( !empty( $wpIlMatch ) ) {
19 $nt = Title::newFromUrl( $wpIlMatch );
20 if($nt ) {
21 $m = $dbr->strencode( strtolower( $nt->getDBkey() ) );
22 $m = str_replace( "%", "\\%", $m );
23 $m = str_replace( "_", "\\_", $m );
24 $sql .= " WHERE LCASE(img_name) LIKE '%{$m}%'";
25 }
26 }
27 if ( "bysize" == $sort ) {
28 $sql .= " ORDER BY img_size DESC";
29 $st = $bysize;
30 } else if ( "byname" == $sort ) {
31 $sql .= " ORDER BY img_name";
32 $st = $byname;
33 } else {
34 $sort = "bydate";
35 $sql .= " ORDER BY img_timestamp DESC";
36 $st = $bydate;
37 }
38 list( $limit, $offset ) = wfCheckLimits( 50 );
39 if ( 0 == $limit ) {
40 $lt = wfMsg( "all" );
41 } else {
42 $lt = $wgLang->formatNum( "${limit}" );
43 $sql .= " LIMIT {$limit}";
44 }
45 $wgOut->addHTML( "<p>" . wfMsg( "imglegend" ) . "</p>\n" );
46
47 $text = wfMsg( "imagelisttext",
48 "<strong>{$lt}</strong>", "<strong>{$st}</strong>" );
49 $wgOut->addHTML( "<p>{$text}\n</p>" );
50
51 $sk = $wgUser->getSkin();
52 $cap = wfMsg( "ilshowmatch" );
53 $sub = wfMsg( "ilsubmit" );
54 $titleObj = Title::makeTitle( NS_SPECIAL, "Imagelist" );
55 $action = $titleObj->escapeLocalURL( "sort={$sort}&limit={$limit}" );
56
57 $wgOut->addHTML( "<form id=\"imagesearch\" method=\"post\" action=\"" .
58 "{$action}\">" .
59 "{$cap}: <input type='text' size='8' name=\"wpIlMatch\" value=\"" .
60 htmlspecialchars( $wpIlMatch ) . "\" /> " .
61 "<input type='submit' name=\"wpIlSubmit\" value=\"{$sub}\" /></form>" );
62 $nums = array( 50, 100, 250, 500 );
63 $here = $wgLang->specialPage( "Imagelist" );
64
65 $fill = "";
66 $first = true;
67 foreach ( $nums as $num ) {
68 if ( ! $first ) { $fill .= " | "; }
69 $first = false;
70
71 $fill .= $sk->makeKnownLink( $here, $wgLang->formatNum( $num ),
72 "sort=byname&limit={$num}&wpIlMatch=" . urlencode( $wpIlMatch ) );
73 }
74 $text = wfMsg( "showlast", $fill, $byname );
75 $wgOut->addHTML( "<p>{$text}<br />\n" );
76
77 $fill = "";
78 $first = true;
79 foreach ( $nums as $num ) {
80 if ( ! $first ) { $fill .= " | "; }
81 $first = false;
82
83 $fill .= $sk->makeKnownLink( $here, $wgLang->formatNum( $num ),
84 "sort=bysize&limit={$num}&wpIlMatch=" . urlencode( $wpIlMatch ) );
85 }
86 $text = wfMsg( "showlast", $fill, $bysize );
87 $wgOut->addHTML( "{$text}<br />\n" );
88
89 $fill = "";
90 $first = true;
91 foreach ( $nums as $num ) {
92 if ( ! $first ) { $fill .= " | "; }
93 $first = false;
94
95 $fill .= $sk->makeKnownLink( $here, $wgLang->formatNum( $num ),
96 "sort=bydate&limit={$num}&wpIlMatch=" . urlencode( $wpIlMatch ) );
97 }
98 $text = wfMsg( "showlast", $fill, $bydate );
99 $wgOut->addHTML( "{$text}</p>\n<p>" );
100
101 $res = $dbr->query( $sql, "wfSpecialImagelist" );
102 while ( $s = $dbr->fetchObject( $res ) ) {
103 $name = $s->img_name;
104 $ut = $s->img_user_text;
105 if ( 0 == $s->img_user ) { $ul = $ut; }
106 else { $ul = $sk->makeLink( $wgLang->getNsText(
107 Namespace::getUser() ) . ":{$ut}", $ut ); }
108
109 $ilink = "<a href=\"" . Image::wfImageUrl( $name ) .
110 "\">{$name}</a>";
111
112 $nb = wfMsg( "nbytes", $wgLang->formatNum( $s->img_size ) );
113 $l = "(" .
114 $sk->makeKnownLink( $wgLang->getNsText(
115 Namespace::getImage() ) . ":{$name}", wfMsg( "imgdesc" ) ) .
116 ") {$ilink} . . {$nb} . . {$ul} . . " .
117 $wgLang->timeanddate( $s->img_timestamp, true );
118
119 if ( "" != $s->img_description ) {
120 $l .= " <em>({$s->img_description})</em>";
121 }
122 $wgOut->addHTML( "{$l}<br />\n" );
123 }
124 $wgOut->addHTML( "</p>" );
125 $dbr->freeResult( $res );
126 }
127
128 ?>